﻿using MediatR;
using Traceability.App.API.Application.Command.Deep;
using Traceability.App.Domain.Traceability;
using Traceability.App.ErrorCode;
using Traceability.App.Infrastructrue.Interface;

namespace Traceability.App.API.Application.Handler.Deep
{
    public class GetDeepHandler : IRequestHandler<GetDeepCommand, APIResult<DeepProcessingModel>>
    {
        private readonly IBaseRepository<DeepProcessingModel> deepRepo;

        public GetDeepHandler(IBaseRepository<DeepProcessingModel> deepRepo)
        {
            this.deepRepo = deepRepo;
        }
        public Task<APIResult<DeepProcessingModel>> Handle(GetDeepCommand request, CancellationToken cancellationToken)
        {
            APIResult<DeepProcessingModel> result = new APIResult<DeepProcessingModel>();
            var res = deepRepo.GetAll().FirstOrDefault(x => x.Batch == request.Batch);
            result.Message = "显示成功";
            result.Data = res;
            result.Code = APIEnum.Ok;
            return Task.FromResult(result);
        }
    }
}
